# -*- coding: utf-8 -*-
from urllib import request
import os

class FangtianxiaImagesPipeline(object):
    def __init__(self):
        self.path = os.path.join(os.path.dirname(os.path.dirname(__file__)),'images')
        if not os.path.exists(self.path):
            os.mkdir(self.path)

    def process_item(self, item, spider):
        ct = item['category']
        print(ct)
        img = item['image_urls']
        print(img)
        ct_path = os.path.join(self.path, ct.strip())
        if not os.path.exists(ct_path):
            print('开始创建  ct')
            os.mkdir(ct_path)

        for imgs in img:
            print('https:'+imgs)
            request.urlretrieve('https:'+imgs,os.path.join(ct_path,imgs.split('/')[-1]))
        print('*' * 150)